<?php
namespace app\index\controller;

use think\Controller;
use app\index\model\Guestbook;
use app\index\model\Archive;
use app\index\model\Arctype;
use app\index\model\Member;
use app\index\model\Addonalbum;

class About extends Common
{
    public function _initialize(){
        parent::_initialize();
//		if(!CheckMemberLogin()){
//			$this->redirect('Login/index');
//		}
    }
    
    public function index()
    {   
		$arcModel = new Archive();
		$typeModel = new Arctype();
		$arcList = $arcModel->alias('a')
							->field('a.*,b.content')
							->join('tf_addonalbum b','a.id=b.aid')
							->where(['a.typeid'=>4,'a.status'=>1])
							->order('a.id ASC')
							->select();
		$this->assign('arcList', $arcList);
		
		$id =input('id') ? input('id') : $arcList[0]['id'];
		$data =  $arcModel->alias('a')
							->field('a.*,b.content')
							->join('tf_addonalbum b','a.id=b.aid')
							->where(['a.typeid'=>4,'a.status'=>1,'a.id'=>$id])
							->find();						
		$this->assign('data',$data);
		$this->assign('id',$id);
		$this->assign('BannerList',banners(4,1));
		$this->assign('webtitle',$data['webtitle'] ? $data['webtitle'] .' - 好融艺' : $data['title'] . ' - 好融艺');
		$this->assign('keywords',$data['keywords']);
		$this->assign('description',$data['description']);
		
        return $this->fetch(); 
    }

	public function feedback(){
		if(request()->isAjax()){
			
			$userId = session('UID');
			if(empty($userId)){
				return ajaxReturn('请先登录');
			}
			$fmodel = new Guestbook();
			$data = input('post.');
			$data['uid'] = $userId;
			$result = $fmodel->allowField(true)->save($data);
			if($result){
				return ajaxReturn('感谢您的反馈');
			}else{
				return ajaxReturn($fmodel->getError());
			}
		}
	}
	
	public function share(){
        $url = input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
		$userId = session('UID');
		if($userId){
			$MemberModel = new Member();
			$invite = $MemberModel->where(['id'=>$userId])->value('invite');
			$url .= "/mobile/#/register?invite=".$invite;
		}
		$this->assign('url', $url);
		return $this->fetch();
	}
	
}
